<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>站点设置</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="__ADMIN_STATIC__/css/oksub.css">
  <script type="text/javascript" src="__STATIC__/lib/loading/okLoading.js"></script>
</head>
<body>
<div class="ok-body">
  <blockquote class="layui-elem-quote">
    <p>信息设置 <a href="{:url('setting/index')}" class="layui-btn layui-btn-primary layui-btn-sm">返回</a></p>
  </blockquote>
  <blockquote class="layui-elem-quote layui-quote-nm">
    <form class="layui-form" action="">
      <div class="layui-form-item">
        <label class="layui-form-label">站点名称</label>
        <div class="layui-input-block">
          <input type="text" name="appname" required value="{$model.appname}"  lay-verify="required" placeholder="请输入站点名称" autocomplete="off" class="layui-input">
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label">站点描述</label>
        <div class="layui-input-block">
          <input type="text" name="description" required  value="{$model.description}"  lay-verify="required" placeholder="请输入站点描述" autocomplete="off" class="layui-input">
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label">站点关键字</label>
        <div class="layui-input-block">
          <input type="text" name="keywords" required value="{$model.keywords}"  lay-verify="required" placeholder="请输入站点关键字" autocomplete="off" class="layui-input">
        </div>
      </div>

      <div class="layui-form-item">
        <label class="layui-form-label">logo</label>
        <div class="layui-input-block">
          <div style="display: flex;">
            <button type="button" class="layui-btn layui-btn-primary" id="up_logo">
              <i class="layui-icon">&#xe67c;</i>上传图片
            </button>
            <input id="logo_input" disabled value="{$model.logo}" type="text" name="logo" autocomplete="off" class="layui-input">
          </div>
          <div id="logo_msg"></div>
          <div class="layui-form-mid layui-word-aux">请选择(252 * 92)的PNG 图片.</div>
        </div>
      </div>

      <div class="layui-form-item">
        <label class="layui-form-label">备案号</label>
        <div class="layui-input-block">
          <input type="text" name="record"  value="{$model.record}" placeholder="站点备案号" autocomplete="off" class="layui-input">
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label">联系邮箱</label>
        <div class="layui-input-block">
          <input type="email" name="email" required value="{$model.email}"  lay-verify="required|email" placeholder="站点联系邮箱" autocomplete="off" class="layui-input">
        </div>
      </div>
      <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">关于我</label>
        <div class="layui-input-block">
          <textarea name="about" placeholder="关于我" class="layui-textarea">{$model.about}</textarea>
        </div>
      </div>

      <div class="layui-form-item">
        <div class="layui-input-block">
          <button class="layui-btn" lay-submit lay-filter="formSetting">立即提交</button>
          <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
      </div>
    </form>

  </blockquote>

</div>
<!--js逻辑-->
<script src="__STATIC__/lib/layui/layui.js"></script>
<script>
    layui.use(["okLayer",'form','upload','jquery','okUtils'], function () {
        let form = layui.form,
            upload = layui.upload,
            okUtils = layui.okUtils,
            $ = layui.jquery;

        okLoading.close();


        //图片上传
        let uploadInst = upload.render({
            elem: '#up_logo'
            , url: "{:url('setting/uploadLogo')}"
            , field: 'logo'
            , done: function (res) {
                //如果上传失败
                if (res.code > 0) {
                    return layer.msg('上传失败');
                }
                //上传成功
                $('#logo_input').val(res.data['src']);
            }
            , error: function () {
                //演示失败状态，并实现重传
                let demoText = $('#logo_msg');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function () {
                    uploadInst.upload();
                });
            }
        });


        //监听提交
        form.on("submit(formSetting)", function (data) {
            okUtils.ajax("{:url('setting/update')}", "post", data.field, true).done(function (response) {
                layer.msg(response.msg,{
                    icon:1
                },function(){
                    window.location.href = '{:url("setting/index")}';
                });

            }).fail(function (error) {
                console.log(error);
            });
            return false;
        });
    });
</script>
</body>
</html>
